package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.domain.DepartmentDomain;
import com.ngc.mall.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 部门控制类
 * @author: chenxiaolin
 * @date 2023/10/28 7:34
**/
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService iDepartmentService;

    @GetMapping("/list")
    @ApiOperation("查询所有部门")
    public ResponseResult<List<DepartmentDomain>> findAll(){
        return ResponseResult.success(iDepartmentService.findAll());
    }

    @GetMapping("/list/enabled")
    @ApiOperation("查询所有启用的部门")
    public ResponseResult<List<DepartmentDomain>> findAllEnabled(){
        return ResponseResult.success(iDepartmentService.findAllEnabled());
    }

    @PostMapping("")
    @ApiOperation("新增部门")
    public ResponseResult<Long> createDepartment(@RequestBody DepartmentDomain domain){
        return ResponseResult.success(iDepartmentService.createDepartment(domain));
    }

    @PutMapping("/id/{id}")
    @ApiOperation("根据id更新部门")
    public ResponseResult<Boolean> updateById(@PathVariable Long id,@RequestBody DepartmentDomain domain){
        return ResponseResult.auto(iDepartmentService.updateById(id,domain));
    }

    @DeleteMapping("/id/{id}")
    @ApiOperation("根据id删除部门")
    public ResponseResult<Boolean> deleteById(@PathVariable Long id){
        return ResponseResult.auto(iDepartmentService.deleteById(id));
    }
}
